package org.nowcoder.leetcode.BSearch;

import java.util.Arrays;

/**
 * Title  : 4. Median of Two Sorted Arrays
 * Source : https://leetcode.cn/problems/median-of-two-sorted-arrays/description/
 * Author : XrazYang
 * Date   : 2023-10-30
 */

public class LeetCode_4 {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        // 常规思路解法： 有点傻
        int[] total = new int[nums1.length + nums2.length];
        System.arraycopy(nums1, 0, total, 0, nums1.length);
        System.arraycopy(nums2, 0, total, nums1.length, nums2.length);
        Arrays.sort(total);
        if (total.length % 2 == 0) {
            int mid = total.length / 2;
            return (total[mid] + total[mid - 1]) / 2.0;
        } else {
            return total[total.length / 2];
        }
    }
}
